home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/perl
-
- sub dokill {
- kill 9,$child if $child;
- }
-
- sub Opengopher {
-
- local($them,$port) = @_;
- $them = 'localhost' unless $them;
-
- $AF_INET = 2;
- $SOCK_STREAM = 1;
-
- $SIG{'INT'} = 'dokill';
-
- $sockaddr = 'S n a4 x8';
-
- chop($hostname = `hostname`);
-
- ($name,$aliases,$proto) = getprotobyname('tcp');
- ($name,$aliases,$port) = getservbyname($port,'tcp')
- unless $port =~ /^\d+$/;;
- ($name,$aliases,$type,$len,$thisaddr) = gethostbyname($hostname);
- ($name,$aliases,$type,$len,$thataddr) = gethostbyname($them);
-
- $this = pack($sockaddr, $AF_INET, 0, $thisaddr);
- $that = pack($sockaddr, $AF_INET, $port, $thataddr);
-
- # Make the socket filehandle.
- socket(S, $AF_INET, $SOCK_STREAM, $proto) || die $!;
-
- # Give the socket an address.
- bind(S, $this) || die $!;
-
- # Call up the server.
- connect(S,$that) || die $!;
-
- # Set socket to be command buffered.
- select(S); $| = 1; select(STDOUT);
-
- }
-
- while ($arg = shift(@ARGV)) {
- if ($arg eq "-l") {
- $LongFlag = 1;
- }
- }
-
- open(GopherFile, "/tmp/.gopher") || die "You haven't run gsetup yet!";
-
- $Firstline = <GopherFile>;
- ($CurrentHost, $Port, $Path) = split('\t',$Firstline);
- &Opengopher( $CurrentHost, $Port);
-
- print S "$Path\n";
-
- while (<S>) {
- chop;
- chop;
- ($ObjName, $Path, $Host, $Port) = split('\t', $_, 6);
- $Name = substr($ObjName, 1);
- $Obj = substr($ObjName, 0, 1);
-
- if ($LongFlag) {
- print "$Host\t$Port\t";
- }
-
- print "$Name" if ($ObjName ne ".");
- print "/" if ($Obj eq "1");
- print "." if ($Obj eq "0");
- print " <?>" if ($Obj eq "7");
-
-
- print "\n";
- }
-